package llll;
import java.util.Scanner;

interface Appliance {
    int weight();
}

class TV implements Appliance {
    int weight;

    TV(int w) {
        this.weight = w;
    }

    public int weight() {
        return weight;
    }
}

class WashMachine implements Appliance {
    int weight;

    WashMachine(int w) {
        this.weight = w;
    }

    public int weight() {
        return weight;
    }
}

class AirCondition implements Appliance {
    int weight;

    AirCondition(int w) {
        this.weight = w;
    }

    public int weight() {
        return weight;
    }
}

class Truck {
    int sum = 0;

    void add(Appliance a) {
        sum += a.weight();
    }
}

public class 运送家电 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Truck truck = new Truck();
        int n = scan.nextInt();
        int id, weight;
        for (int i = 0; i < n; i++) {
            id = scan.nextInt();
            weight = scan.nextInt();

            Appliance[] data = new Appliance[]{new TV(weight), new WashMachine(weight), new AirCondition(weight)};
            truck.add(data[id-1]);
        }
        System.out.println(truck.sum);
    }
}
